package library.net.retrofit;

import android.support.annotation.NonNull;

import okhttp3.MediaType;

public class RxContextType {

    public final static String IMAGE_PNG = "image/png";
    public final static String IMAGE_JPG = "image/jpg";
    public static final String IMAGE_DATA = "image/*; charset=utf-8";
    public static final String TEXT_DATA = "text/plain; charset=utf-8";
    public static final String JSON_DATA = "application/json; charset=utf-8";
    public static final String FORM_DATA = "multipart/form-data; charset=utf-8";
    public static final String MARKDOWN_DATA = "text/x-markdown; charset=utf-8";
    public static final String VIDEO_DATA = "video/*";
    public static final String AUDIO_DATA = "audio/*";
    public static final String FILE_DATA = "application/octet-stream";
    public static final String APK_DATA = "application/vnd.android.package-archive";

    /**
     * png
     */
    public static final MediaType MEDIA_TYPE_PNG = MediaType
            .parse(IMAGE_PNG);
    /**
     * jpg
     */
    public static final MediaType MEDIA_TYPE_JPG = MediaType
            .parse(IMAGE_JPG);
    /**
     * image
     */
    public static final MediaType MEDIA_TYPE_IMAGE = MediaType
            .parse(IMAGE_DATA);
    /**
     * text
     */
    public static final MediaType MEDIA_TYPE_TEXT = MediaType
            .parse(TEXT_DATA);
    /**
     * json
     */
    public static final MediaType MEDIA_TYPE_JSON = MediaType
            .parse(JSON_DATA);
    /**
     * markdown
     */
    public static final MediaType MEDIA_TYPE_MARKDOWN = MediaType
            .parse(MARKDOWN_DATA);
    /**
     * form
     */
    public static final MediaType MEDIA_TYPE_FORM = MediaType
            .parse(FORM_DATA);
    /**
     * video
     */
    public static final MediaType MEDIA_TYPE_VIDEO = MediaType
            .parse(VIDEO_DATA);
    /**
     * audio
     */
    public static final MediaType MEDIA_TYPE_AUDIO = MediaType
            .parse(AUDIO_DATA);
    /**
     * file stream
     */
    public static final MediaType MEDIA_TYPE_STREAM = MediaType
            .parse(FILE_DATA);
    /**
     * apk
     */
    public static final MediaType MEDIA_TYPE_APK = MediaType
            .parse(APK_DATA);

    /**
     * @author Created by qiang.hou on 2017/12/14.
     * @version 1.0
     */
    public enum ContentType {
        /**
         * application/json
         */
        JSON,
        /**
         * text
         */
        TEXT,
        /**
         * AUDIO
         */
        AUDIO,
        /**
         *
         */
        VIDEO,
        /**
         * image
         */
        IMAGE,
        /**
         * application/vnd.android.package-archive
         */
        APK,
        /**
         * multipart/form-data
         */
        FORM
    }

    public static MediaType typeToMediaType(@NonNull ContentType type) {
        switch (type) {
            case APK:
                return MEDIA_TYPE_APK;
            case VIDEO:
                return MEDIA_TYPE_VIDEO;
            case AUDIO:
                return MEDIA_TYPE_AUDIO;
            case IMAGE:
                return MEDIA_TYPE_IMAGE;
            case TEXT:
                return MEDIA_TYPE_TEXT;
            case JSON:
                return MEDIA_TYPE_JSON;
            case FORM:
                return MEDIA_TYPE_FORM;
            default:
                return MEDIA_TYPE_TEXT;
        }
    }

    public static String typeToString(@NonNull ContentType type) {
        switch (type) {
            case APK:
                return APK_DATA;
            case VIDEO:
                return VIDEO_DATA;
            case AUDIO:
                return AUDIO_DATA;
            case IMAGE:
                return IMAGE_DATA;
            case TEXT:
                return TEXT_DATA;
            case JSON:
                return JSON_DATA;
            case FORM:
                return FORM_DATA;
            default:
                return TEXT_DATA;
        }
    }
}
